
// You must define this vvv in the client-code
//def tile_screen:byte[40,25]		@ 33792 
def tile_color:byte[40, 25]			@ 55296


sub tile_drawscreen(ref map:byte[], ref tiles:byte[]) {
	def map_idx:byte = 0
	def tile_id:byte
	def tile_idx:word

	def sx:byte
	def sy:byte = 1

	for my:0..5 {
		sx = 0
		for mx:0..9 {
			tile_id = map[map_idx]
			tile_idx = tile_id
			tile_idx = tile_idx << 4

			for ty:0..3 {
				for tx:0..3 {
					def tmp_x:byte
					def tmp_y:byte

					tmp_x = sx + tx
					tmp_y = sy + ty

					tile_screen[tmp_x, tmp_y] = tiles[tile_idx]
					inc tile_idx
				}
			}
			inc map_idx
			sx = sx + 4
		}
		sy = sy + 4
		sx = 0
	}
}
